### 2.9
###1### copy模块    向145服务器发送test.sh 文件
ansible 192.168.142.145 -m copy -a "src=/root/shell/test.sh dest=/root/shell/test.sh"

###2###  copy模块   向db下的所有服务器发送test.sh文件
vi /etc/ansible/hosts

[db]
192.168.142.145
192.168.142.151

ansible db -m copy -a "src=/root/shell/test.sh dest=/root/shell/test.sh"

###3### shell 模块，执行命令
ansible db -m shell -a "ls;pwd"


###4###  script模块，专门执行脚本sh
ansible db -m shell -a "chmod +x /root/shell/test.sh"
ansible db -m script -a "/root/shell/test.sh"


###5### command模块，远程主机执行命令
ansible db -m command -a "hostname"


###6### cron模块，定时任务
ansible db -m cron -a "minute=0 hour=0 job='/bin/sh /root/server/test.sh >/dev/null 2>&1'"

#参考博客：https://www.cnblogs.com/jasonminghao/p/12635616.html


# 2.9
# 先执行playbook，分发shell脚本文件
# 配置文件如下
---
- hosts: db
  tasks:
    - name: "分发shell文件"
      copy: src="/root/shell/test.sh" dest="/root/shell/test.sh"

#执行palybook.yaml
ansible-playbook playbook.yaml

# 再执行cron模块，设置定时任务
ansible db -m cron -a "name='清理日志' minute=* hour=* day='1' month=* weekday=* job='/bin/bash /root/shell/test.sh' "